package org.dxy.domain.game.database;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dxy.domain.game.model.entity.GameEntity;
import org.dxy.domain.game.model.entity.PieceEntity;
import org.dxy.domain.game.model.entity.PlayerEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.*;

@Component
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GameDatabase {
    // 玩家内存
    private Map<Long, PlayerEntity> playerEntityMap = new HashMap<>();

    // 游戏内存
    private GameEntity gameEntity;

    // 棋子内存
    private Map<Long, PieceEntity> pieceEntityMap = new HashMap<>();


    // 清空棋子内存
    public void clearPieceEntityMap(){
        pieceEntityMap.clear();
    }

    // 添加玩家
    public void addPlayer(PlayerEntity player) {
        playerEntityMap.put(player.getPlayerId(), player);
    }

    // 获取玩家
    public PlayerEntity getPlayer(Long playerId) {
        return playerEntityMap.get(playerId);
    }


    public List<PlayerEntity> getAllPlayer() {
        return new ArrayList<>(playerEntityMap.values());
    }

    // 添加游戏
    public void addGame(GameEntity gameEntity) {
        this.gameEntity = gameEntity;
    }

    // 获取游戏
    public GameEntity getGame() {
        return gameEntity;
    }

    // 添加棋子
    public void addPiece(PieceEntity piece) {
        pieceEntityMap.put(piece.getPieceId(), piece);
    }

    // 获取单个棋子
    public PieceEntity getPiece(Long pieceId) {
        return pieceEntityMap.get(pieceId);
    }

    // 获取所有棋子列表
    public List<PieceEntity> getAllPieces() {
        return new ArrayList<>(pieceEntityMap.values());
    }
}
